home *** CD-ROM | disk | FTP | other *** search
- Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
- From: reckdahl@leland.Stanford.EDU (Keith Reckdahl)
- Newsgroups: comp.lang.c++,comp.lang.c++.moderated
- Subject: Pointer Typecasts
- Date: 30 Jan 1996 00:13:29 -0000
- Organization: Stanford University, CA 94305, USA
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: vandevod@cs.rpi.edu
- Message-ID: <4ejnr9$cpf@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: 29 Jan 1996 15:15:40 -0800
-
- We've been having problems with the following pointer
- typecast: We have 4 classes A,B,C, and D
- B inherits from A
- C inherits from A
- D inherits from both B and C
- Note: We've have also tried to inherit D from B and C
- using the virtual keyword so that only one instance
- of A is instantiated, but this does not seem to affect
- the problem. We try to typecast a pointer from A to D
- meaning, in the code, we have
- A *a1;
- D *d1;
- d1 = (D *)a1;
- And this does not work. We get an illegal typecast
- compiler error. We've tried this on a variety of
- compilers, including CODE WARRIOR, BORLAND, and MPW.
-
- We thought that typecasting pointers is a simple
- matter because all pointers are simply addresses.
- What are we doing wrong?
-
- Keith Reckdahl, Paul Mitiguy, Margaret Becker
- reckdahl@leland.stanford.edu
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-